var prefix = api + "/admin/tenant";

$(function () {
  var status_datas = dictByType('status_type')
  renderDictFilter('#status', 'status_type')
  var addFlag = permissions.admin_systenant_add
  var editFlag = permissions.admin_systenant_edit
  var deleteFlag = permissions.admin_systenant_del
  //没有新增权限的话删除新增按钮
  if (!addFlag) {
    $('#addBtn').remove()
  }
  var options = {
    url: prefix + "/page",
    updateUrl: "/pages/sysadm/tenant/tenantEdit",
    removeUrl: prefix + "/{id}",
    sortName: "name",
    sortOrder: "asc",
    modalName: "租户",
    columns: [
      {
        title: "序号",
        formatter: function (value, row, index) {
          return $.table.serialNumber(index);
        }
      },
      {
        field: 'name',
        title: '租户名称',
        formatter: function (value, row, index) {
          return '<a href="javascript:$.operate.view(' + "'" + row.id + "'" + ')">' + value + '</a>';
        },
      },
      {
        field: 'code',
        title: '租户编码'
      },
      {
        field: 'status',
        title: '状态',
        align: 'center',
        formatter: function (value, row, index) {
          return $.table.selectDictLabel(status_datas, value);
        }
      },
      {
        field: 'startTime',
        title: '开始时间',
        sortable: true
      }, {
        field: 'endTime',
        title: '结束时间',
        sortable: true
      }, {
        title: '操作',
        formatter: function (value, row, index) {
          var actions = [];
          if (editFlag) {
            actions.push('<a class="btn btn-success btn-xs" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a> ');
          }
          if (deleteFlag) {
            actions.push('<a class="btn btn-danger btn-xs" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除</a> ');
          }

          return actions.join('');
        }
      }]
  };
  $.table.init(options);
});

//获取状态字典
